package cn.com.easy.permission.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import cn.com.easy.permission.model.UserModel;

/**
 * user infomation dao
 * 
 * @auth nibili 2015-2-3
 */
public interface UserDao extends JpaRepository<UserModel, Long>, JpaSpecificationExecutor<UserModel> {

	/**
	 * find by login name and password
	 * 
	 * @return
	 * @auth nibili 2015-2-3
	 */
	@Query("select t from UserModel t where t.loginname=?1 and (t.password=?2 and t.password is not null and t.password<>'') ")
	public UserModel findByLoginnameAndPassword(String loginName, String passWord);

	/**
	 * find by login name
	 * 
	 * @auth nibili 2015-2-2 12:28:07
	 */
	public UserModel findByLoginname(String loginName);

	/**
	 * 登录名或者真实姓名相似查询
	 * 
	 * @param searchText
	 * @param pageable
	 * @return
	 * @author nibili 2015年12月16日
	 */
	@Query("select t from UserModel t where t.loginname like %?1% or t.realname like %?1%")
	public Page<UserModel> findLikeLoginnameOrRealname(String searchText, Pageable pageable);
}
